/**
 * 项目相关接口的mock数据
 */

// 模拟项目列表数据
const projectList = [
  {
    id: '1',
    name: '区块链手表系列',
    description: '限量版区块链智能手表系列，每个手表都有独特的NFT认证。',
    progress: 68,
    target: '100000',
    current: '68000',
    participants: 245,
    deadline: '2025-08-15',
    status: 'active',
    image: 'https://images.unsplash.com/photo-1523275335684-37898b6baf30?q=80&w=1000&auto=format&fit=crop',
    earnings: '150.00',
    currency: 'USDT',
    createdAt: '2023-01-01 12:00:00',
    updatedAt: '2023-01-01 12:00:00'
  },
  {
    id: '2',
    name: '元宇宙可穿戴设备',
    description: '为元宇宙设计的可穿戴设备，支持虚拟现实和增强现实功能。',
    progress: 42,
    target: '200000',
    current: '84000',
    participants: 312,
    deadline: '2025-09-30',
    status: 'active',
    image: 'https://images.unsplash.com/photo-1546868871-7041f2a55e12?q=80&w=1000&auto=format&fit=crop',
    earnings: '45.00',
    currency: 'HDFS',
    createdAt: '2023-02-01 12:00:00',
    updatedAt: '2023-02-01 12:00:00'
  },
  {
    id: '3',
    name: '智能家居生态系统',
    description: '基于区块链的智能家居生态系统，实现设备间的无缝连接和智能控制。',
    progress: 75,
    target: '150000',
    current: '112500',
    participants: 189,
    deadline: '2025-07-20',
    status: 'active',
    image: 'https://images.unsplash.com/photo-1558002038-1055907df827?q=80&w=1000&auto=format&fit=crop',
    earnings: '78.50',
    currency: 'HDFS',
    createdAt: '2023-03-01 12:00:00',
    updatedAt: '2023-03-01 12:00:00'
  }
]

/**
 * 获取项目列表
 * @param {Object} params 查询参数
 * @returns {Object} 项目列表数据
 */
export function getProjectList(params) {
  const { page = 1, size = 10, status = '' } = params
  
  // 根据查询条件过滤
  let filteredList = [...projectList]
  if (status) {
    filteredList = filteredList.filter(item => item.status === status)
  }
  
  const total = filteredList.length
  const list = filteredList.slice((page - 1) * size, page * size)
  
  return {
    code: 0,
    message: '获取项目列表成功',
    data: {
      list: list,
    },
    total: total,
    page: parseInt(page),
    size: parseInt(size)
  }
}

/**
 * 获取项目详情
 * @param {string|number} id 项目ID
 * @returns {Object} 项目详情
 */
export function getProjectDetail(id) {
  const project = projectList.find(item => item.id === id.toString())
  
  if (project) {
    return {
      code: 0,
      message: '获取项目详情成功',
      data: project
    }
  } else {
    return {
      code: 404,
      message: '项目不存在',
      data: null
    }
  }
}

/**
 * 参与项目
 * @param {Object} data 参与数据
 * @returns {Object} 参与结果
 */
export function joinProject(data) {
  return {
    code: 0,
    message: '参与项目成功',
    data: {
      orderNo: 'PJ' + Date.now(), // 订单号
      projectId: data.projectId,
      amount: data.amount, // 参与金额
      joinTime: new Date().toISOString().replace('T', ' ').substring(0, 19), // 参与时间
      status: 'success' // 状态：success-成功，failed-失败
    }
  }
}